package org.xteam.sled.semantic.exp;

public class ExpSlice extends Exp {

	private Exp expr;
	private int low;
	private int width;

	public ExpSlice(Exp expr, int low, int width) {
		this.expr = expr;
		this.low = low;
		this.width = width;
	}

	public int width() {
		return width;
	}
	
	public int low() {
		return low;
	}
	
	public Exp getExpr() {
		return expr;
	}
	
	public int hashCode() {
		return expr.hashCode() + low + width;
	}
	
	public boolean equals(Object o) {
		return (o instanceof ExpSlice)
			&& ((ExpSlice)o).low == low
			&& ((ExpSlice)o).width == width
			&& ((ExpSlice)o).expr.equals(expr);
	}

	@Override
	public void visit(IExpVisitor visitor) {
		visitor.visitSlice(this);
	}
	
	public String toString() {
		return expr.toString() + "@[" + low + ":" + (low + width - 1) + "]";
	}

}
